package com.fengye.algorithms.leecode;

/**
 * @Author fengye
 * @Date 2023/5/10 9:20
 **/
public class MergeStringsAlternately1768 {
    public static void main(String[] args) {
        System.out.println(new MergeStringsAlternately1768().mergeAlternately("a", "qpr"));
    }

    public String mergeAlternately(String word1, String word2) {
        int l1 = word1.length();
        int l2 = word2.length();

        int a=0, b=0;
        StringBuilder sb = new StringBuilder();
        while (a < l1 && b < l2) {
            sb.append(word1.charAt(a++)).append(word2.charAt(b++));
        }

        if(a == l1) {
            sb.append(word2.substring(b));
        }

        if(b == l2) {
            sb.append(word1.substring(a));
        }

        return sb.toString();
    }
}
